﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace text1
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void login_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            String username, password;
            username = textBox1.Text;
            password = textBox2.Text;
            String myconn = @"server=LAPTOP-NHBSREVG;database=LOGIN;uid=sa;pwd=990823";//数据库实例连接字符串
            SqlConnection sqlConnection = new SqlConnection(myconn);//新建数据库连接实例
            sqlConnection.Open();//打开数据库连接
            String sql = "select SID,SKEY from PEOPLE where SID='" + username + "'and SKEY='" + password + "'";//SQL语句实现表数据的读取
            SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            if (sqlDataReader.HasRows)//满足用户名与密码一致，进入下一个界面
            {

                this.Hide();
                main nf = new main();
                nf.ShowDialog();
                this.Dispose();


            }
            else//如果登录失败，询问是否注册新用户
            {
                DialogResult dr = MessageBox.Show("是否注册新用户？", "登录失败", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)//打开注册界面
                {
                    this.Hide();
                    login2 nf2 = new login2();
                    nf2.ShowDialog();
                    this.Dispose();
                }
                else
                {
                    this.Show();
                }
            }


        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

            textBox2.PasswordChar = '*';

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            login2 nf2 = new login2();
            nf2.ShowDialog();
            this.Dispose();

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)

            {

                //复选框被勾选，明文显示

                textBox2.PasswordChar = new char();

            }

            else

            {

                //复选框被取消勾选，密文显示

                textBox2.PasswordChar = '*';

            }
        }

     

            private void textBox1_TextChanged(object sender, EventArgs e)
        {
           

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
